﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TBR.Common.Serialization
{
    public class BinarySerializationHelper : ISerializationHelper
    {
        public void Serialize(Stream streamObject, object objectForSerialization)
        {
            if (objectForSerialization == null || streamObject == null)
                return;

            var ser = new SimpleBinarySerializer(objectForSerialization.GetType());
            ser.WriteObject(streamObject, objectForSerialization);
        }

        public object Deserialize(Stream streamObject, Type serializedObjectType)
        {
            if (serializedObjectType == null || streamObject == null)
                return null;

            var ser = new SimpleBinarySerializer(serializedObjectType);
            return ser.ReadObject(streamObject);
        }
    }
}
